<extend name="template/base_index" />

<block name="area_header">
    <link rel="stylesheet" type="text/css" media="all" href="__CSS__/wxshop.css">
    <link type="text/css" rel="stylesheet" src="__CDN__/jquery-uploadify/3.2.1/uploadify.css" />
    <script type="text/javascript" src="__CDN__/jquery-uploadify/3.2.1/jquery.uploadify.min.js"></script>
    <link type="text/css" rel="stylesheet" href="__CDN__/select2/3.5.2/select2.css" />
    <script type="text/javascript" src="__CDN__/select2/3.5.2/select2.min.js"></script>
    <script type="text/javascript" src="__CDN__/select2/3.5.2/select2_locale_zh-CN.js"></script>
</block>

<block name="area_body">
    {:W('Menus/topbar')}
    <div class="admin-main container-fluid">
        {:W('Menus/left')}
        <div class="admin-main-content">
            {:W('Menus/breadcrumb')}

            <div class="col-main">
                <div class="main-hd">
                    <h2>查看帖子</h2>
                </div>
                <div class="main-bd clearfix" style="padding: 0 10px;margin-top: 0px;">
                    <form class="productForm form-horizontal" method="post">
                        <input type="hidden" name="tid" value="{$thread_info.tid}" />
                        <h3><i>●</i>基本信息</h3>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">所属板块</label>
                            <div class="col-lg-10 col-md-10">
                                {$forum.name}
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">标题</label>
                            <div class="col-lg-10 col-md-10">
                                {$thread.subject}
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">内容</label>
                            <div class="col-lg-10 col-md-10">
                                <div style="width: 600px; height: 150px; border: 1px solid #ccc; background: #FFF; padding: 5px; overflow-y: scroll;">{$post.message}</div>
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">作者</label>
                            <div class="col-lg-10 col-md-10">
                                <a href="{:U('Admin/CustomerInfo/index',array('id'=>$post['author_id']))}">{$post.author}</a>
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">提交时间</label>
                            <div class="col-lg-10 col-md-10">
                                {$post.dateline|date='Y-m-d H:i:s',###}
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2">图片</label>
                            <div class="col-lg-10 col-md-10">
                                <div class="wxuploaderimg clearfix product-imglist "  data-maxitems="10">
                                    <notempty name="attachment">
                                        <volist name="attachment" id="vo">
                                            <div class="pull-left clearfix img-item">
                                                <a data-toggle="thumbnail" data-original-title="点击查看原图" href="{:U('Api/Picture/index',array('id'=>$vo['aid']))}" target="_blank"><img src="{:U('Api/Picture/index',array('id'=>$vo['aid'],'size'=>120))}" data-imageid=""/></a>&nbsp;
                                            </div>
                                        </volist>
                                        <else />无
                                    </notempty>
                                </div>
                            </div>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 clearfix">
                            <label for="" class="control-label col-lg-2 col-md-2"></label>
                            <div class="col-lg-10 col-md-10">
                                <a class="btn btn-default btn-sm" href="javascript:history.back(-1);"><i class="fa fa-reply"></i>返回</a>
                            </div>
                        </div>

                    </form>
                </div>
            </div>

            <include file="template/wxpicture" />
        </div>
    <!-- END admin-main-content -->
    </div>
    <!-- END admin-main-->
</block>

<block name="area_footer">
    <script type="text/javascript" ></script>


    <script type="text/javascript">
        window.ServicesURL = {
            groupGetAll:"{:U('Admin/WxshopGroup/groups')}",
            groupAdd:"{:U('Admin/WxshopGroup/add')}",
            cateAllProp:"{:U('Admin/Product/cateAllProp')}",
            skulist:"{:U('Admin/Product/skulist')}",
        };
    </script>
    <script type="text/javascript">
        //国别选择时的操作
        function initCountry(){
            $(".dt_origin_country").change(function(){
                var val = $(".dt_origin_country").find("option:selected").text();
                $("input[name='source']").val(val);
            });
            $(".dt_origin_country").change();
        }

        //初始化select2 控件
        function initSelect2(){
            $('select').select2();
        }

        function getData(){

            $(".property").val("");
            $(".propsel").each(function(index,item){
                $propvalue = $(item).val();
                if($propvalue != "=请选择="){
                    $(".property").val($(".property").val()+$propvalue+";");
                }
            });

            var main_img = $(".main_img .img-preview img").attr("data-imageid");
            if(main_img){
                $("#main_img").val(main_img);
            }

            $("#img").val("");
            $(".product-imglist .img-preview img").each(function(index,item){
                $("#img").val($("#img").val()+$(item).attr("data-imageid")+",");
                //alert($("#img").val());
            });


            var img_post = $(".img_post .img-preview img").attr("data-imageid");
            if(img_post){
                $("#img_post").val(img_post);
            }

            var img_post_bg = $(".img_post_bg .img-preview img").attr("data-imageid");
            if(img_post_bg){
                $("#img_post_bg").val(img_post_bg);
            }
            //alert($("#img").val());
        }


        function check(){
            getData();
            var txt = $(".js_product_name").val();
            var len = txt.replace(/[^\x00-\xff]/g, 'xx').length ;
            if(len == 0){
                $.scojs_message('商品名称必须填写', $.scojs_message.TYPE_ERROR);
                return false;
            }
            if(len > 30){
                $.scojs_message('商品名称不能超过30个字', $.scojs_message.TYPE_ERROR);
                return false;
            }
            return true;
        }

        function appendProp(list){

            $ele = $(".js_prop .prop-list");
            $ele.empty();
            for(var i=0;i<list.length;i++){
                //创建一个dropdown
                $propName = $('<span>'+list[i].name+'</span>');
                $prop = $('<div class="dropdown dropdown-toggle"></div>');
                $ele.append($("<div class='prop-item' ></div>").attr("data-id",list[i].id).append($propName).append($prop));

                if(list[i].property_value){

                    $propValue = $("<select class='propsel propvalue-list dropdown-menu'></select>");
                    $prop.append($propValue);
                    var propvaluelist = list[i].property_value;
                    $propValue.append("<option class='propvalue-item'>=请选择=</option>");
                    for(var j=0;j<propvaluelist.length;j++){
                        $propValueItem = $("<option class='propvalue-item'></option>");
                        $propValueItem.attr("data-id",propvaluelist[j].id).text(propvaluelist[j].valuename).val(list[i].id+","+propvaluelist[j].id);
                        $propValue.append($propValueItem);
                    }
                }

            }


        }



        //商品属性
        function queryProp() {


            $(".js_prop .loading").show();
            var last_cate = "{$cate_id}";
            $.post(window.ServicesURL.cateAllProp, {
                cate_id: last_cate
            }).done(function(data) {
                //
                if (data.status) {
                    if(data.info == null){
                        $ele = $(".js_prop .prop-list");
                        $ele.html("无属性");
                        return ;
                    }
                    appendProp(data.info);
                    $(".propsel").select2({
                        placeholder: "=选择=",
                        language: "zh-CN",
                    });
                } else {
                    $.scojs_message('添加失败!', $.scojs_message.TYPE_ERROR);
                }
            }).always(function(){
                $(".js_prop .loading").hide();
            });
        }

        function productProp(){

            $(".js_prop .prop-list").click(function(ev){
                $ele = $(ev.target);
                if(!$ele.hasClass('link_a')){
                    return ;
                }
                $propitem = $ele.parents(".prop-item");
                $ele.addClass("selected");
                $propitem.find("button.dropdown-toggle").html($ele.text()+"<span class='caret'></span>");
            });

            setTimeout(queryProp,700);
        }

        $(function() {
            productProp();
            initCountry();
            initSelect2();
            //图片上传
            wxuploadimg.init({cont:".wxuploaderimg"});
            //
            $(".js_frm_gp_buylimit input[type=radio]").click(function(){
                console.log($(this).val());
                console.log($(".js_frm_gp_buylimit input[type=text]"));
                if($(this).val() == 1){
                    $(".js_frm_gp_buylimit input[type=text]").removeClass("hidden");
                }else{
                    $(".js_frm_gp_buylimit input[type=text]").addClass("hidden");
                }
            });
            $(".js_frm_gp_buylimit input[type=radio][value=0]").click(function(){
                $(".js_frm_gp_buylimit input[type=text]").attr('value',0);
                $(".js_frm_gp_buylimit input[type=text]").val(0);
            });
            $(".js_frm_gp_buylimit input[type=text]").change(function(){
                var tmp = $(this).val();
                $(this).attr("value",tmp);
            });
            $(".js_delete:first").click(function(){
                $(".main_img .img-preview img").attr("data-imageid","");
                $("#main_img").attr("value","");
                $("#main_img").val("");
            });
        })

    </script>

</block>